package io.gitee.geminidev.bot.websocket;

import io.gitee.geminidev.bot.event.Callback;
import io.gitee.geminidev.bot.type.EventType;
import io.gitee.geminidev.bot.util.GroupedSet;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft;

import java.net.URI;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author gemini
 * @Date 2023/4/20 0:03
 * @description:
 */
public abstract class AbstractBotWebSocket extends WebSocketClient implements BotWebSocket {

    /**
     * 线程安全的Boolean -是否收到消息
     */
    protected AtomicBoolean hasMessage = new AtomicBoolean(false);

    /**
     * 线程安全的Boolean -是否已经连接
     */
    protected AtomicBoolean hasConnection = new AtomicBoolean(false);

    /**
     * 重新连接标识
     */
    protected AtomicBoolean hasReconnect = new AtomicBoolean(false);

    /** 最新序列号 */
    protected AtomicInteger serialNumber = new AtomicInteger();

    /** token */
    protected String token;

    protected int intents;

    protected String sessionId;

    protected GroupedSet<EventType, Callback> callbacks;

    public AbstractBotWebSocket(URI serverUri) {
        super(serverUri);
        this.callbacks = new GroupedSet<>();
    }

    public AbstractBotWebSocket(URI serverUri, Draft protocolDraft) {
        super(serverUri, protocolDraft);
    }

    public AbstractBotWebSocket(URI serverUri, Map<String, String> httpHeaders) {
        super(serverUri, httpHeaders);
    }

    public AbstractBotWebSocket(URI serverUri, Draft protocolDraft, Map<String, String> httpHeaders) {
        super(serverUri, protocolDraft, httpHeaders);
    }

    public AbstractBotWebSocket(URI serverUri, Draft protocolDraft, Map<String, String> httpHeaders, int connectTimeout) {
        super(serverUri, protocolDraft, httpHeaders, connectTimeout);
    }
}
